﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using PPI.Data;
using PPI.Entities;
using PPI.Entities.Interface;
using PPI.Mobile;
using VMind.Global;
namespace PPI.ServiceLogic
{
    public class LVendor : IMobileTable
    {
        public static EVendor SelectData(Int32 VendorID, string connectionKey)
        {
            DataRow _Datarow = DVendor.SelectData(VendorID, connectionKey).Tables[0].Rows[0];
            EVendor _Vendor = new EVendor();
            
            _Vendor.VendorId = ConvertHelper.ToInt32(_Datarow["VendorID"]);
            _Vendor.Name = ConvertHelper.Tostring(_Datarow["Name"]);
            _Vendor.Status = ConvertHelper.Tostring(_Datarow["Status"]);
            return _Vendor;
        }

        public static List<EVendor> SelectAllIdName(string connectionKey)
        {
            DataSet ds = DVendor.SelectAllIdName(connectionKey);
            List<EVendor> _vendorList = new List<EVendor>();
            EVendor _vendor;
            foreach (DataRow  dr in ds.Tables[0].Rows)
            {
                _vendor = new EVendor();
                _vendor.VendorId = ConvertHelper.ToInt32(dr["VendorId"]);
                _vendor.Name = ConvertHelper.Tostring(dr["Name"]);
                _vendorList.Add(_vendor);
            }
            return _vendorList;
        }

        public List<EMobileQuery> CreateInsertMobileQuery(string connectionKey)
        {
            List<EMobileQuery> listQueries = new List<EMobileQuery>();
            StringBuilder _Query = new StringBuilder();

            DataTable dt = DVendor.SelectAllIdName(connectionKey).Tables[0];
            listQueries.Add(new EMobileQuery("Delete tb_Vendor"));
            foreach (DataRow dr in dt.Rows)
            {
                listQueries.Add(new EMobileQuery("insert into tb_Vendor values (" + ConvertHelper.ToInt32(dr["VendorId"]) + ",'" + ConvertHelper.Tostring(dr["Name"]) + "')"));
            }
            return listQueries;
        }
    }
}
